clear

cd "XXX/Replication/"

// --- RELATIVE MOBILITY, PUBLIC ---
import excel using "data_for_importing/QuintileTransitions.xlsx", firstrow // Quintile Transitions comes from online_data_tables.xls
save "intermediate_files/QuintileTransitions.dta", replace

// Fix zip code variable name in crosswalk file
use "data_for_importing/cw_zip99_cz.dta"
rename zip99nov inputzip // Standardize variable name
tostring inputzip, replace // Convert zip codes into strings
drop if inputzip == "."
save "intermediate_files/cz_rename.dta", replace

// CZ relative mobility perception data
use "data_for_importing/DART0035_A_OUTPUT-ZIP-CORRECTED.DTA", clear
gen cz_per_q5q1 = Q19grid_1_1/100 // Grow up to be in richest 100 families
gen cz_per_q4q1 = Q19grid_2_1/100
gen cz_per_q3q1 = Q19grid_3_1/100
gen cz_per_q2q1 = Q19grid_4_1/100
gen cz_per_q1q1 = Q19grid_5_1/100 // Grow up to be in poorest 100 families

// US relative mobility perception data
gen us_per_q5q1 = Q14grid_1_1/100 // Grow up to be in richest 100 families
gen us_per_q4q1 = Q14grid_2_1/100
gen us_per_q3q1 = Q14grid_3_1/100
gen us_per_q2q1 = Q14grid_4_1/100
gen us_per_q1q1 = Q14grid_5_1/100 // Grow up to be in poorest 100 families

save "intermediate_files/2a_Full_Data_Public.dta", replace

// Fix 38 zip codes
import excel using "data_for_importing/zipcode research1.xlsx", firstrow cellrange(A1:C85) clear
reshape wide zipcode, i(ID) j(Version, string)
rename zipcodeNew inputzip
duplicates list inputzip
duplicates drop inputzip, force
duplicates list inputzip
save "intermediate_files/ZipCodeResearch.dta", replace
use "intermediate_files/2a_Full_Data_Public.dta", clear
tostring inputzip, replace
merge m:1 inputzip using "intermediate_files/ZipCodeResearch.dta", keepusing(zipcodeOld)
tab _merge
drop _merge
replace inputzip = zipcodeOld if zipcodeOld != ""
drop zipcodeOld

// Merge commuting zones with BLW perception data (based on zip codes)
merge m:1 inputzip using "intermediate_files/cz_rename.dta"
tab _merge
drop if _merge == 2
drop _merge

// Merge Chetty actual data with BLW perception data (based on commuting zones)
merge m:1 cz using "intermediate_files/QuintileTransitions.dta", keepusing(q1q1 q2q1 q3q1 q4q1 q5q1)
tab _merge
drop if _merge == 2
drop _merge

// Generate errors for relative mobility perceptions, CZ (perception - actual)
gen pub_err_cz_q1q1 = cz_per_q1q1-q1q1
gen pub_err_cz_q2q1 = cz_per_q2q1-q2q1
gen pub_err_cz_q3q1 = cz_per_q3q1-q3q1
gen pub_err_cz_q4q1 = cz_per_q4q1-q4q1
gen pub_err_cz_q5q1 = cz_per_q5q1-q5q1

// Generate errors for relative mobility perceptions, US (perception - actual)
gen pub_err_us_q1q1 = us_per_q1q1-0.337 // Values from Table II of Chetty et al. 2014 QJE
gen pub_err_us_q2q1 = us_per_q2q1-0.280
gen pub_err_us_q3q1 = us_per_q3q1-0.184
gen pub_err_us_q4q1 = us_per_q4q1-0.123
gen pub_err_us_q5q1 = us_per_q5q1-0.075

save "intermediate_files/2a_Full_Data_Public.dta", replace


// --- ABSOLUTE MOBILITY, PUBLIC ---
// Absolute mobility perception data
use "intermediate_files/2a_Full_Data_Public.dta", clear
gen us_per_abs = Q31/100 // Perception of absolute mobility in the US
gen state_per_abs = Q21/100 // Perception of absolute mobility in your state
save "intermediate_files/2a_Full_Data_Public.dta", replace

// Chetty actual data 
use "data_for_importing/table2_state_absmob_by_cohort.dta"
drop if cohort != 1980 // Limit sample to 1980 cohort
save "intermediate_files/absmob1980.dta", replace

// Merge Chetty actual data with BLW perception data (based on states)
use "intermediate_files/2a_Full_Data_Public.dta", clear
gen state_fips = inputstate
merge m:1 state_fips using "intermediate_files/absmob1980.dta", keepusing(cohort_mean)
tab state_fips
tab _merge
drop if _merge == 2
drop _merge

// Generate errors for absolute mobility perceptions
gen pub_err_state_abs = state_per_abs-cohort_mean
gen pub_err_us_abs = us_per_abs-0.5 // Value from Chetty (2016) working paper abstract
su pub_err_state_abs
su pub_err_us_abs

save "intermediate_files/2a_Full_Data_Public.dta", replace


// --- ABSOLUTE MOBILITY, ELITES ---
// Civic Pulse data
clear
import delimited using "data_for_importing/CivicPulse_GrossmannNyhan_Spring_2020.csv", varnames(1)
replace q31 = "" if q31 == "NA"
replace q21 = "" if q21 == "NA"
destring q31, replace
destring q21, replace
gen us_per_abs = q31/100 // Perception of absolute mobility in the US
gen state_per_abs = q21/100 // Perception of absolute mobility in your state

// Merge Chetty actual data with Civic Pulse perception data
rename state_code state_fips
replace state_fips = "" if state_fips == "NA"
replace state_fips = "25" if state_abb == "MA" /* CivicPulse had two mistakes */
destring state_fips, replace
merge m:1 state_fips using "intermediate_files/absmob1980.dta", keepusing(cohort_mean)
tab _merge
drop if _merge == 2
drop _merge

// Generate errors for absolute mobility perceptions
gen elite_err_state_abs = state_per_abs-cohort_mean
gen elite_err_us_abs = us_per_abs-0.5 // Value from Chetty (2016) working paper abstract
su elite_err_state_abs
su elite_err_us_abs

// --- RELATIVE MOBILITY, ELITES ---
/* 35 NAs for scenario 2 but not scenario 1 */
replace gn_scenario2_5 = "" if gn_scenario2_5 == "NA"
destring gn_scenario2_5, replace
replace gn_scenario2_4 = "" if gn_scenario2_4 == "NA"
destring gn_scenario2_4, replace
replace gn_scenario2_3 = "" if gn_scenario2_3 == "NA"
destring gn_scenario2_3, replace
replace gn_scenario2_2 = "" if gn_scenario2_2 == "NA"
destring gn_scenario2_2, replace
replace gn_scenario2_1 = "" if gn_scenario2_1 == "NA"
destring gn_scenario2_1, replace
// CZ relative mobility perception data
gen cz_per_q1q1 = gn_scenario1_5 if gn_scenario1 == "Local Area" // Grow up to be in poorest 100 families
replace cz_per_q1q1 = gn_scenario2_5 if gn_scenario1 == "US"
gen cz_per_q2q1 = gn_scenario1_4 if gn_scenario1 == "Local Area"
replace cz_per_q2q1 = gn_scenario2_4 if gn_scenario1 == "US"
gen cz_per_q3q1 = gn_scenario1_3 if gn_scenario1 == "Local Area"
replace cz_per_q3q1 = gn_scenario2_3 if gn_scenario1 == "US"
gen cz_per_q4q1 = gn_scenario1_2 if gn_scenario1 == "Local Area"
replace cz_per_q4q1 = gn_scenario2_2 if gn_scenario1 == "US"
gen cz_per_q5q1 = gn_scenario1_1 if gn_scenario1 == "Local Area" // Grow up to be in richest 100 families
replace cz_per_q5q1 = gn_scenario2_1 if gn_scenario1 == "US"
/* Divide by 100 */
replace cz_per_q1q1 = cz_per_q1q1/100
replace cz_per_q2q1 = cz_per_q2q1/100
replace cz_per_q3q1 = cz_per_q3q1/100
replace cz_per_q4q1 = cz_per_q4q1/100
replace cz_per_q5q1 = cz_per_q5q1/100

// US relative mobility perception data
gen us_per_q1q1 = gn_scenario1_5 if gn_scenario1 == "US" // Grow up to be in poorest 100 families
replace us_per_q1q1 = gn_scenario2_5 if gn_scenario1 == "Local Area"
gen us_per_q2q1 = gn_scenario1_4 if gn_scenario1 == "US"
replace us_per_q2q1 = gn_scenario2_4 if gn_scenario1 == "Local Area"
gen us_per_q3q1 = gn_scenario1_3 if gn_scenario1 == "US"
replace us_per_q3q1 = gn_scenario2_3 if gn_scenario1 == "Local Area"
gen us_per_q4q1 = gn_scenario1_2 if gn_scenario1 == "US"
replace us_per_q4q1 = gn_scenario2_2 if gn_scenario1 == "Local Area"
gen us_per_q5q1 = gn_scenario1_1 if gn_scenario1 == "US" // Grow up to be in richest 100 families
replace us_per_q5q1 = gn_scenario2_1 if gn_scenario1 == "Local Area"
/* Divide by 100 */
replace us_per_q1q1 = us_per_q1q1/100
replace us_per_q2q1 = us_per_q2q1/100
replace us_per_q3q1 = us_per_q3q1/100
replace us_per_q4q1 = us_per_q4q1/100
replace us_per_q5q1 = us_per_q5q1/100

// Rename & destring Chetty variables
rename pchildq1parq1 q1q1
rename pchildq2parq1 q2q1
rename pchildq3parq1 q3q1
rename pchildq4parq1 q4q1
rename pchildq5parq1 q5q1
replace q1q1 = "" if q1q1 == "NA"
replace q2q1 = "" if q2q1 == "NA"
replace q3q1 = "" if q3q1 == "NA"
replace q4q1 = "" if q4q1 == "NA"
replace q5q1 = "" if q5q1 == "NA"
destring q1q1, replace
destring q2q1, replace
destring q3q1, replace
destring q4q1, replace
destring q5q1, replace

// Generate errors for relative mobility perceptions, CZ (perception - actual)
gen elite_err_cz_q1q1 = cz_per_q1q1-q1q1
gen elite_err_cz_q2q1 = cz_per_q2q1-q2q1
gen elite_err_cz_q3q1 = cz_per_q3q1-q3q1
gen elite_err_cz_q4q1 = cz_per_q4q1-q4q1
gen elite_err_cz_q5q1 = cz_per_q5q1-q5q1

// Generate errors for relative mobility perceptions, US (perception - actual)
gen elite_err_us_q1q1 = us_per_q1q1-0.337 // Values from Table II of Chetty et al. 2014 QJE
gen elite_err_us_q2q1 = us_per_q2q1-0.280
gen elite_err_us_q3q1 = us_per_q3q1-0.184
gen elite_err_us_q4q1 = us_per_q4q1-0.123
gen elite_err_us_q5q1 = us_per_q5q1-0.075

save "intermediate_files/2b_Full_Data_Elite.dta", replace

// --- APPENDING ELITES TO PUBLIC ---
// Fix public data
use "intermediate_files/2a_Full_Data_Public.dta", clear
/* Elite ID */
gen elite = "public"
/* Errors */
clonevar err_us_q1q1 = pub_err_us_q1q1
clonevar err_us_q2q1 = pub_err_us_q2q1
clonevar err_us_q3q1 = pub_err_us_q3q1
clonevar err_us_q4q1 = pub_err_us_q4q1
clonevar err_us_q5q1 = pub_err_us_q5q1
clonevar err_cz_q1q1 = pub_err_cz_q1q1
clonevar err_cz_q2q1 = pub_err_cz_q2q1
clonevar err_cz_q3q1 = pub_err_cz_q3q1
clonevar err_cz_q4q1 = pub_err_cz_q4q1
clonevar err_cz_q5q1 = pub_err_cz_q5q1
clonevar err_state_abs = pub_err_state_abs
clonevar err_us_abs = pub_err_us_abs
/* Education */
decode educ7, gen(ed1)
drop educ7
gen education1 = 1 if ed1 == "Did not graduate from high school"
replace education1 = 2 if ed1 == "High school diploma or the equivalent (GED)"
replace education1 = 3 if ed1 == "Some college"
replace education1 = 3 if ed1 == "Associate's degree"
replace education1 = 4 if ed1 == "Bachelor's degree"
replace education1 = 5 if ed1 == "Master's degree"
replace education1 = 5 if ed1 == "Professional or doctorate degree"
drop ed1
decode educ, gen (ed2)
drop educ
gen education2 = 1 if ed2 == "No HS"
replace education2 = 2 if ed2 == "High school graduate"
replace education2 = 3 if ed2 == "Some college"
replace education2 = 4 if ed2 == "2-year"
replace education2 = 4 if ed2 == "4-year"
replace education2 = 5 if ed2 == "Post-grad"
drop ed2
tab education1
tab education2
drop education2
rename education1 education
/* Absolute mobility perception variable names */
gen state_absmob_per = Q21 // Remove labels
gen us_absmob_per = Q31
/* Partisan */
drop pid3_t
decode pid3, gen(party1)
drop pid3
gen partisan1 = ""
replace partisan1 = "Democrat" if party1 == "Democrat"
replace partisan1 = "Republican" if party1 == "Republican"
replace partisan1 = "Other" if party1 == "Independent"
replace partisan1 = "Other" if party1 == "Other"
replace partisan1 = "Other" if party1 == "Not sure"
replace partisan1 = "NA" if party1 == ""
decode pid7, gen(party2)
drop pid7
gen partisan2 = "Democrat" if party2 == "Strong Democrat"
replace partisan2 = "Democrat" if party2 == "Not very strong Democrat"
replace partisan2 = "Democrat" if party2 == "Lean Democrat"
replace partisan2 = "Republican" if party2 == "Strong Republican"
replace partisan2 = "Republican" if party2 == "Not very strong Republican"
replace partisan2 = "Republican" if party2 == "Lean Republican"
replace partisan2 = "Other" if party2 == "Independent"
replace partisan2 = "Other" if party2 == "Not sure"
replace partisan2 = "Other" if party2 == "Don't know"
replace partisan2 = "NA" if party2 == ""
tab partisan1
tab partisan2
drop partisan2
drop party1
drop party2
rename partisan1 partisan // pid3
/* Ideology */
gen ideology = .
replace ideology = 1 if ideo7 == 5 // Slightly liberal
replace ideology = 1 if ideo7 == 6 // Somewhatliberal
replace ideology = 1 if ideo7 == 7 // Very liberal
replace ideology = 2 if ideo7 == 1 // Very conservative
replace ideology = 2 if ideo7 == 2 // Somewhat conservative
replace ideology = 2 if ideo7 == 3 // Slightly conservative
replace ideology = 3 if ideo7 == 4 // Moderate; middle of the road
drop ideo7
/* Race & Ethnicity */
gen nonhispanic_white = 0 // This is ok because BLW's "race" variable has no missing values, so everything will be 0 or 1
replace nonhispanic_white = 1 if race == 1
tab nonhispanic_white
drop race
drop race_other
drop ethnicity
/* Q15 flip numbers */
rename Q15grid_1 Q15grid1
gen opp_wealth = 5 if Q15grid1 == 1
replace opp_wealth = 4 if Q15grid1 == 2
replace opp_wealth = 3 if Q15grid1 == 3
replace opp_wealth = 2 if Q15grid1 == 4
replace opp_wealth = 1 if Q15grid1 == 5
drop Q15grid1
rename Q15grid_2 Q15grid2
gen opp_race = 5 if Q15grid2 == 1
replace opp_race = 4 if Q15grid2 == 2
replace opp_race = 3 if Q15grid2 == 3
replace opp_race = 2 if Q15grid2 == 4
replace opp_race = 1 if Q15grid2 == 5
drop Q15grid2
rename Q15grid_3 Q15grid3
gen opp_edu = 5 if Q15grid3 == 1
replace opp_edu = 4 if Q15grid3 == 2
replace opp_edu = 3 if Q15grid3 == 3
replace opp_edu = 2 if Q15grid3 == 4
replace opp_edu = 1 if Q15grid3 == 5
drop Q15grid3
rename Q15grid_4 Q15grid4
gen opp_work = 5 if Q15grid4 == 1
replace opp_work = 4 if Q15grid4 == 2
replace opp_work = 3 if Q15grid4 == 3
replace opp_work = 2 if Q15grid4 == 4
replace opp_work = 1 if Q15grid4 == 5
drop Q15grid4
rename Q15grid_5 Q15grid5
gen opp_nochild = 5 if Q15grid5 == 1
replace opp_nochild = 4 if Q15grid5 == 2
replace opp_nochild = 3 if Q15grid5 == 3
replace opp_nochild = 2 if Q15grid5 == 4
replace opp_nochild = 1 if Q15grid5 == 5
drop Q15grid5
/* Q15 str */
gen public_q15_1 = "NA"
replace public_q15_1 = "Essential" if opp_wealth == 5
replace public_q15_1 = "Very important" if opp_wealth == 4
replace public_q15_1 = "Fairly important" if opp_wealth == 3
replace public_q15_1 = "Not very important" if opp_wealth == 2
replace public_q15_1 = "Not important at all" if opp_wealth == 1
gen public_q15_2 = "NA"
replace public_q15_2 = "Essential" if opp_race == 5
replace public_q15_2 = "Very important" if opp_race == 4
replace public_q15_2 = "Fairly important" if opp_race == 3
replace public_q15_2 = "Not very important" if opp_race == 2
replace public_q15_2 = "Not important at all" if opp_race == 1
gen public_q15_3 = "NA"
replace public_q15_3 = "Essential" if opp_edu == 5
replace public_q15_3 = "Very important" if opp_edu == 4
replace public_q15_3 = "Fairly important" if opp_edu == 3
replace public_q15_3 = "Not very important" if opp_edu == 2
replace public_q15_3 = "Not important at all" if opp_edu == 1
gen public_q15_4 = "NA"
replace public_q15_4 = "Essential" if opp_work == 5
replace public_q15_4 = "Very important" if opp_work == 4
replace public_q15_4 = "Fairly important" if opp_work == 3
replace public_q15_4 = "Not very important" if opp_work == 2
replace public_q15_4 = "Not important at all" if opp_work == 1
gen public_q15_5 = "NA"
replace public_q15_5 = "Essential" if opp_nochild == 5
replace public_q15_5 = "Very important" if opp_nochild == 4
replace public_q15_5 = "Fairly important" if opp_nochild == 3
replace public_q15_5 = "Not very important" if opp_nochild == 2
replace public_q15_5 = "Not important at all" if opp_nochild == 1
rename public_q15_1 opp_wealth_str
rename public_q15_2 opp_race_str
rename public_q15_3 opp_edu_str
rename public_q15_4 opp_work_str
rename public_q15_5 opp_nochild_str
/* Sex */
gen sex = "NA"
replace sex = "Male" if gender == 1
replace sex = "Female" if gender == 2
drop gender
/* Birthyear 1927-2001*/
gen birth = ""
replace birth = "1926 - 1930" if birthyr >= 1926 & birthyr <= 1930
replace birth = "1931 - 1935" if birthyr >= 1931 & birthyr <= 1935
replace birth = "1936 - 1940" if birthyr >= 1936 & birthyr <= 1940
replace birth = "1941 - 1945" if birthyr >= 1941 & birthyr <= 1945
replace birth = "1946 - 1950" if birthyr >= 1946 & birthyr <= 1950
replace birth = "1951 - 1955" if birthyr >= 1951 & birthyr <= 1955
replace birth = "1956 - 1960" if birthyr >= 1956 & birthyr <= 1960
replace birth = "1961 - 1965" if birthyr >= 1961 & birthyr <= 1965
replace birth = "1966 - 1970" if birthyr >= 1966 & birthyr <= 1970
replace birth = "1971 - 1975" if birthyr >= 1971 & birthyr <= 1975
replace birth = "1976 - 1980" if birthyr >= 1976 & birthyr <= 1980
replace birth = "1981 - 1985" if birthyr >= 1981 & birthyr <= 1985
replace birth = "1986 - 1990" if birthyr >= 1986 & birthyr <= 1990
replace birth = "1991 - 1995" if birthyr >= 1991 & birthyr <= 1995
replace birth = "1996 - 2000" if birthyr >= 1996 & birthyr <= 2000
replace birth = "2001 - 2005" if birthyr >= 2001 & birthyr <= 2005
drop birthyr
drop age
drop age9
/* Drop public variables */
drop consent
drop Q19grid_1_1
drop Q19grid_2_1
drop Q19grid_3_1
drop Q19grid_4_1
drop Q19grid_5_1
drop Q14grid_1_1
drop Q14grid_2_1
drop Q14grid_3_1
drop Q14grid_4_1
drop Q14grid_5_1
drop inputstate
drop inputzip
drop starttime
drop endtime
drop cz
/* Save */
save "intermediate_files/2a_Full_Data_Public.dta", replace

// Fix elite data
use "intermediate_files/2b_Full_Data_Elite.dta", clear
/* Elite ID */
gen elite = "elite"
/* Errors */
clonevar err_us_q1q1 = elite_err_us_q1q1
clonevar err_us_q2q1 = elite_err_us_q2q1
clonevar err_us_q3q1 = elite_err_us_q3q1
clonevar err_us_q4q1 = elite_err_us_q4q1
clonevar err_us_q5q1 = elite_err_us_q5q1
clonevar err_cz_q1q1 = elite_err_cz_q1q1
clonevar err_cz_q2q1 = elite_err_cz_q2q1
clonevar err_cz_q3q1 = elite_err_cz_q3q1
clonevar err_cz_q4q1 = elite_err_cz_q4q1
clonevar err_cz_q5q1 = elite_err_cz_q5q1
clonevar err_state_abs = elite_err_state_abs
clonevar err_us_abs = elite_err_us_abs
/* Education */
rename education educ
gen education = 1 if educ == "Less than high school"
replace education = 2 if educ == "High school graduate"
replace education = 3 if educ == "Technical/trade school"
replace education = 3 if educ == "Some college"
replace education = 4 if educ == "College graduate"
replace education = 4 if educ == "Some graduate school"
replace education = 5 if educ == "Graduate degree"
drop educ
/* Absolute mobility perception variable names */
rename q21 state_absmob_per
rename q31 us_absmob_per
/* Partisan */
gen partisan = ""
replace partisan = "Democrat" if pid == "Democrat"
replace partisan = "Republican" if pid == "Republican"
replace partisan = "Other" if pid == "Other" | pid == "Independent"
replace partisan = "NA" if pid == "NA"
// drop if partisan == "NA"
tab partisan
drop pid
drop v64
/* Ideology */
rename ideology ideology1
gen ideology = .
replace ideology = 1 if ideology1 == "Very liberal"
replace ideology = 1 if ideology1 == "Somewhat liberal"
replace ideology = 2 if ideology1 == "Somewhat conservative"
replace ideology = 2 if ideology1 == "Very conservative"
replace ideology = 3 if ideology1 == "Not sure"
replace ideology = 3 if ideology1 == "Moderate, middle of the road"
drop ideology1
tab ideology
/* Race & Ethnicity */
drop race_other_flag
save "intermediate_files/2b_Full_Data_Elite.dta", replace
clear
import delimited using "data_for_importing/Race_data_supplement_R.csv", varnames(1)
rename v3 race_other
save "intermediate_files/race_supplement.dta", replace
use "intermediate_files/2b_Full_Data_Elite.dta", clear
merge 1:1 cp_id using "intermediate_files/race_supplement.dta", keepusing(race_other)
tab _merge
drop _merge
replace nonhispanic_white = 0 if race_other == 0
replace nonhispanic_white = 1 if race_other == 1
replace nonhispanic_white = . if race_other == 2
drop race_other
tab nonhispanic_white
/* Q15 */
gen opp_wealth = 1 if q15_1 == "Not important at all"
replace opp_wealth = 2 if q15_1 == "Not very important"
replace opp_wealth = 3 if q15_1 == "Fairly important"
replace opp_wealth = 4 if q15_1 == "Very important"
replace opp_wealth = 5 if q15_1 == "Essential"
gen opp_race = 1 if q15_2 == "Not important at all"
replace opp_race = 2 if q15_2 == "Not very important"
replace opp_race = 3 if q15_2 == "Fairly important"
replace opp_race = 4 if q15_2 == "Very important"
replace opp_race = 5 if q15_2 == "Essential"
gen opp_edu = 1 if q15_3 == "Not important at all"
replace opp_edu = 2 if q15_3 == "Not very important"
replace opp_edu = 3 if q15_3 == "Fairly important"
replace opp_edu = 4 if q15_3 == "Very important"
replace opp_edu = 5 if q15_3 == "Essential"
gen opp_work = 1 if q15_4 == "Not important at all"
replace opp_work = 2 if q15_4 == "Not very important"
replace opp_work = 3 if q15_4 == "Fairly important"
replace opp_work = 4 if q15_4 == "Very important"
replace opp_work = 5 if q15_4 == "Essential"
gen opp_nochild = 1 if q15_5 == "Not important at all"
replace opp_nochild = 2 if q15_5 == "Not very important"
replace opp_nochild = 3 if q15_5 == "Fairly important"
replace opp_nochild = 4 if q15_5 == "Very important"
replace opp_nochild = 5 if q15_5 == "Essential"
rename q15_1 opp_wealth_str
rename q15_2 opp_race_str
rename q15_3 opp_edu_str
rename q15_4 opp_work_str
rename q15_5 opp_nochild_str
/* caseid */
rename cp_id caseid
/* Drop elite variables */
drop gn_scenario1_1
drop gn_scenario1_2
drop gn_scenario1_3
drop gn_scenario1_4
drop gn_scenario1_5
drop gn_scenario2_1
drop gn_scenario2_2
drop gn_scenario2_3
drop gn_scenario2_4
drop gn_scenario2_5
drop v1
drop complete
drop startdate
drop enddate
drop gn_scenario1
drop gn_timer1_firstclick
drop gn_timer1_lastclick
drop gn_timer1_pagesubmit
drop gn_timer1_clickcount
drop gn_timer2_firstclick
drop gn_timer2_lastclick
drop gn_timer2_pagesubmit
drop gn_timer2_clickcount
drop gn_timer3_firstclick
drop gn_timer3_lastclick
drop gn_timer3_pagesubmit
drop gn_timer3_clickcount
drop gn_timer4_firstclick
drop gn_timer4_lastclick
drop gn_timer4_pagesubmit
drop gn_timer4_clickcount
drop gn_timer5_firstclick
drop gn_timer5_lastclick
drop gn_timer5_pagesubmit
drop gn_timer5_clickcount
drop parenthetical_excluded
drop state_abb
drop pid_lean
drop pid_3
drop czname
drop counties_in_cz
drop cz
/* Save */
save "intermediate_files/2b_Full_Data_Elite.dta", replace

// Append
clear
use "intermediate_files/2a_Full_Data_Public.dta"
append using "intermediate_files/2b_Full_Data_Elite.dta"
save "intermediate_files/2c_Full_Data_Appended.dta", replace

// --- ANALYSIS ---
// svyset [pweight=weight]
// svy: tab race
// svy: tab ethnicity
// replace partisan = "" if partisan == "NA"

// Partisan
gen partisannum = .
replace partisannum = 1 if partisan == "Democrat"
replace partisannum = 2 if partisan == "Other"
replace partisannum = 3 if partisan == "Republican"
label def partisanlab 1 "Dem" 2 "Other" 3 "Rep"
label val partisannum partisanlab
gen elitenum = .
replace elitenum = 1 if elite == "elite"
replace elitenum = 0 if elite == "public"
label def elitelab 0 Public 1 Elite
label val elitenum elitelab

// Control dummies
* Sex
tab sex, gen(female)
rename female1 female
rename female2 male
* Age
gen age1829 = (birth == "1991 - 1995" | birth == "1996 - 2000" | birth == "2001 - 2005") if birth!= "NA"
gen age3044 = (birth == "1986 - 1990" | birth == "1981 - 1985" | birth == "1976 - 1980") if birth!= "NA"
gen age4564 = (birth == "1971 - 1975" | birth == "1966 - 1970" | birth == "1961 - 1965" | birth == "1956 - 1960") if birth!= "NA"
gen age65plus = (birth == "1951 - 1955" | birth == "1946 - 1950"| birth == "1941 - 1945"| birth == "1936 - 1940"| birth == "1931 - 1935"| birth == "1926 - 1930"| birth == "1911 - 1915") if birth!= "NA"
tab age1829
tab age3044
tab age4564
tab age65plus
tab birth
* Race
gen nonwhite = .
replace nonwhite = 1 if nonhispanic_white == 0
replace nonwhite = 0 if nonhispanic_white == 1
tab nonhispanic_white
tab nonwhite
* College
gen college = .
replace college = 0 if education == 1 | education == 2 | education == 3
replace college = 1 if education == 4 | education == 5
tab education
tab college

// Absolute Errors
gen absval_err_us_q5q1 = abs(err_us_q5q1)
gen absval_err_us_q4q1 = abs(err_us_q4q1)
gen absval_err_us_q3q1 = abs(err_us_q3q1)
gen absval_err_us_q2q1 = abs(err_us_q2q1)
gen absval_err_us_q1q1 = abs(err_us_q1q1)
gen absval_err_cz_q5q1 = abs(err_cz_q5q1)
gen absval_err_cz_q4q1 = abs(err_cz_q4q1)
gen absval_err_cz_q3q1 = abs(err_cz_q3q1)
gen absval_err_cz_q2q1 = abs(err_cz_q2q1)
gen absval_err_cz_q1q1 = abs(err_cz_q1q1)
gen absval_err_us_abs = abs(err_us_abs)
gen absval_err_state_abs = abs(err_state_abs)

save "intermediate_files/2c_Full_Data_Appended.dta", replace

// Import Brier and Log Scores
use "intermediate_files/2c_Full_Data_Appended.dta", clear
merge 1:1 caseid using "intermediate_files/1a_brier_log_output.dta", keepusing(rel_cz_brierscore rel_us_brierscore abs_state_brierscore abs_us_brierscore rel_cz_logscore rel_us_logscore abs_state_logscore abs_us_logscore)
tab _merge
drop _merge
save "intermediate_files/2d_brier_log.dta", replace



// TABLE 1: Errors
reg err_us_q5q1 ib2.partisannum##elitenum female college nonwhite age3044 age4564 age65plus, robust
est store US_Q5
*Dem/Rep mass polarization:
lincom 1.partisannum-3.partisannum
*Dem/Rep elite polarization:
lincom (1.partisannum+1.partisannum#1.elite)-(3.partisannum+3.partisannum#1.elite) 
*difference in mass/elite polarization:
lincom 1.partisannum#1.elite - 3.partisannum#1.elite

reg err_cz_q5q1 ib2.partisannum##elitenum female college nonwhite age3044 age4564 age65plus, robust
est store CZ_Q5
*Dem/Rep mass polarization:
lincom 1.partisannum-3.partisannum
*Dem/Rep elite polarization:
lincom (1.partisannum+1.partisannum#1.elite)-(3.partisannum+3.partisannum#1.elite) 
*difference in mass/elite polarization:
lincom 1.partisannum#1.elite - 3.partisannum#1.elite

reg err_us_abs ib2.partisannum##elitenum female college nonwhite age3044 age4564 age65plus, robust
est store US_Absolute
*Dem/Rep mass polarization:
lincom 1.partisannum-3.partisannum
*Dem/Rep elite polarization:
lincom (1.partisannum+1.partisannum#1.elite)-(3.partisannum+3.partisannum#1.elite) 
*difference in mass/elite polarization:
lincom 1.partisannum#1.elite - 3.partisannum#1.elite

reg err_state_abs ib2.partisannum##elitenum female college nonwhite age3044 age4564 age65plus, robust
est store State_Absolute
*Dem/Rep mass polarization:
lincom 1.partisannum-3.partisannum
*Dem/Rep elite polarization:
lincom (1.partisannum+1.partisannum#1.elite)-(3.partisannum+3.partisannum#1.elite) 
*difference in mass/elite polarization:
lincom 1.partisannum#1.elite - 3.partisannum#1.elite

estout US_Q5 CZ_Q5 US_Absolute State_Absolute using "Tables/1 Errors.tex", label style(tex) replace varwidth(25) collabels("") cells(b(star fmt(%9.3f)) se(par fmt(%9.3f))) stats(r2 N, fmt(%9.2f %9.0f) labels("N")) starlevels(* 0.05 ** 0.01 *** 0.005)



// TABLE 1a: Errors, weighting public
svyset [pweight=weight]
svy,subpop(if elitenum==0): reg err_us_q5q1 ib2.partisannum female college nonwhite age3044 age4564 age65plus
est store US_Q5

svy,subpop(if elitenum==0): reg err_cz_q5q1 ib2.partisannum female college nonwhite age3044 age4564 age65plus
est store CZ_Q5

svy,subpop(if elitenum==0): reg err_us_abs ib2.partisannum female college nonwhite age3044 age4564 age65plus
est store US_Absolute

svy,subpop(if elitenum==0): reg err_state_abs ib2.partisannum female college nonwhite age3044 age4564 age65plus
est store State_Absolute

estout US_Q5 CZ_Q5 US_Absolute State_Absolute using "Tables/1a Errors_Public.tex", label style(tex) replace varwidth(25) collabels("") cells(b(star fmt(%9.3f)) se(par fmt(%9.3f))) stats(r2 N, fmt(%9.2f %9.0f) labels("N")) starlevels(* 0.05 ** 0.01 *** 0.005)
use "intermediate_files/2d_brier_log.dta", clear 



// TABLE 1b: Errors, weighting elites
svyset [pweight=weight]
svy,subpop(if elitenum==1): reg err_us_q5q1 ib2.partisannum female college nonwhite age3044 age4564 age65plus
est store US_Q5

svy,subpop(if elitenum==1): reg err_cz_q5q1 ib2.partisannum female college nonwhite age3044 age4564 age65plus
est store CZ_Q5

svy,subpop(if elitenum==1): reg err_us_abs ib2.partisannum female college nonwhite age3044 age4564 age65plus
est store US_Absolute

svy,subpop(if elitenum==1): reg err_state_abs ib2.partisannum female college nonwhite age3044 age4564 age65plus
est store State_Absolute

estout US_Q5 CZ_Q5 US_Absolute State_Absolute using "Tables/1b Errors_Elites.tex", label style(tex) replace varwidth(25) collabels("") cells(b(star fmt(%9.3f)) se(par fmt(%9.3f))) stats(r2 N, fmt(%9.2f %9.0f) labels("N")) starlevels(* 0.05 ** 0.01 *** 0.005)
use "intermediate_files/2d_brier_log.dta", clear 


// TABLE 2: Accuracy
reg absval_err_us_q5q1 ib2.partisannum##elitenum female college nonwhite age3044 age4564 age65plus, robust
est store US_Q5
*Dem/Rep mass polarization:
lincom 1.partisannum-3.partisannum
*Dem/Rep elite polarization:
lincom (1.partisannum+1.partisannum#1.elite)-(3.partisannum+3.partisannum#1.elite) 
*difference in mass/elite polarization:
lincom 1.partisannum#1.elite - 3.partisannum#1.elite

reg absval_err_cz_q5q1 ib2.partisannum##elitenum female college nonwhite age3044 age4564 age65plus, robust
est store CZ_Q5
*Dem/Rep mass polarization:
lincom 1.partisannum-3.partisannum
*Dem/Rep elite polarization:
lincom (1.partisannum+1.partisannum#1.elite)-(3.partisannum+3.partisannum#1.elite) 
*difference in mass/elite polarization:
lincom 1.partisannum#1.elite - 3.partisannum#1.elite

reg absval_err_us_abs ib2.partisannum##elitenum female college nonwhite age3044 age4564 age65plus, robust
est store US_Absolute
*Dem/Rep mass polarization:
lincom 1.partisannum-3.partisannum
*Dem/Rep elite polarization:
lincom (1.partisannum+1.partisannum#1.elite)-(3.partisannum+3.partisannum#1.elite)
*difference in mass/elite polarization:
lincom 1.partisannum#1.elite - 3.partisannum#1.elite

reg absval_err_state_abs ib2.partisannum##elitenum female college nonwhite age3044 age4564 age65plus, robust
est store State_Absolute
*Dem/Rep mass polarization:
lincom 1.partisannum-3.partisannum
*Dem/Rep elite polarization:
lincom (1.partisannum+1.partisannum#1.elite)-(3.partisannum+3.partisannum#1.elite) 
*difference in mass/elite polarization:
lincom 1.partisannum#1.elite - 3.partisannum#1.elite

estout US_Q5 CZ_Q5 US_Absolute State_Absolute using "Tables/2 Accuracy.tex", label style(tex) replace varwidth(25) collabels("") cells(b(star fmt(%9.3f)) se(par fmt(%9.3f))) stats(r2 N, fmt(%9.2f %9.0f) labels("N")) starlevels(* 0.05 ** 0.01 *** 0.005)



// TABLE 2a: Accuracy, weighting public
svyset [pweight=weight]
svy,subpop(if elitenum==0): reg absval_err_us_q5q1 ib2.partisannum female college nonwhite age3044 age4564 age65plus
est store US_Q5

svy,subpop(if elitenum==0): reg absval_err_cz_q5q1 ib2.partisannum female college nonwhite age3044 age4564 age65plus
est store CZ_Q5

svy,subpop(if elitenum==0): reg absval_err_us_abs ib2.partisannum female college nonwhite age3044 age4564 age65plus
est store US_Absolute

svy,subpop(if elitenum==0): reg absval_err_state_abs ib2.partisannum female college nonwhite age3044 age4564 age65plus
est store State_Absolute

estout US_Q5 CZ_Q5 US_Absolute State_Absolute using "Tables/2a Accuracy_Public.tex", label style(tex) replace varwidth(25) collabels("") cells(b(star fmt(%9.3f)) se(par fmt(%9.3f))) stats(r2 N, fmt(%9.2f %9.0f) labels("N")) starlevels(* 0.05 ** 0.01 *** 0.005)
use "intermediate_files/2d_brier_log.dta", clear 



// TABLE 2b: Accuracy, weighting elites
svyset [pweight=weight]
svy,subpop(if elitenum==0): reg absval_err_us_q5q1 ib2.partisannum female college nonwhite age3044 age4564 age65plus
est store US_Q5

svy,subpop(if elitenum==0): reg absval_err_cz_q5q1 ib2.partisannum female college nonwhite age3044 age4564 age65plus
est store CZ_Q5

svy,subpop(if elitenum==0): reg absval_err_us_abs ib2.partisannum female college nonwhite age3044 age4564 age65plus
est store US_Absolute

svy,subpop(if elitenum==0): reg absval_err_state_abs ib2.partisannum female college nonwhite age3044 age4564 age65plus
est store State_Absolute

estout US_Q5 CZ_Q5 US_Absolute State_Absolute using "Tables/2b Accuracy_Elites.tex", label style(tex) replace varwidth(25) collabels("") cells(b(star fmt(%9.3f)) se(par fmt(%9.3f))) stats(r2 N, fmt(%9.2f %9.0f) labels("N")) starlevels(* 0.05 ** 0.01 *** 0.005)
use "intermediate_files/2d_brier_log.dta", clear 



// TABLE B1: Error_Q1Q1
reg err_us_q1q1 ib2.partisannum##elitenum female college nonwhite age3044 age4564 age65plus, robust
est store US
*Dem/Rep mass polarization:
lincom 1.partisannum-3.partisannum
*Dem/Rep elite polarization:
lincom (1.partisannum+1.partisannum#1.elite)-(3.partisannum+3.partisannum#1.elite) 
*difference in mass/elite polarization:
lincom 1.partisannum#1.elite - 3.partisannum#1.elite

reg err_cz_q1q1 ib2.partisannum##elitenum female college nonwhite age3044 age4564 age65plus, robust
est store CZ
*Dem/Rep mass polarization:
lincom 1.partisannum-3.partisannum
*Dem/Rep elite polarization:
lincom (1.partisannum+1.partisannum#1.elite)-(3.partisannum+3.partisannum#1.elite) 
*difference in mass/elite polarization:
lincom 1.partisannum#1.elite - 3.partisannum#1.elite

estout US CZ using "Tables/B1 Error_Q1Q1.tex", label style(tex) replace varwidth(25) collabels("") cells(b(star fmt(%9.3f)) se(par fmt(%9.3f))) stats(r2 N, fmt(%9.2f %9.0f) labels("N")) starlevels(* 0.05 ** 0.01 *** 0.005)



// TABLE B2: Accuracy_Rel
reg absval_err_us_q1q1 ib2.partisannum##elitenum female college nonwhite age3044 age4564 age65plus, robust
est store US_Q1
*Dem/Rep mass polarization:
lincom 1.partisannum-3.partisannum
*Dem/Rep elite polarization:
lincom (1.partisannum+1.partisannum#1.elite)-(3.partisannum+3.partisannum#1.elite) 
*difference in mass/elite polarization:
lincom 1.partisannum#1.elite - 3.partisannum#1.elite

reg absval_err_cz_q1q1 ib2.partisannum##elitenum female college nonwhite age3044 age4564 age65plus, robust
est store CZ_Q1
*Dem/Rep mass polarization:
lincom 1.partisannum-3.partisannum
*Dem/Rep elite polarization:
lincom (1.partisannum+1.partisannum#1.elite)-(3.partisannum+3.partisannum#1.elite) 
*difference in mass/elite polarization:
lincom 1.partisannum#1.elite - 3.partisannum#1.elite

reg absval_err_us_q5q1 ib2.partisannum##elitenum female college nonwhite age3044 age4564 age65plus, robust
est store US_Q5
*Dem/Rep mass polarization:
lincom 1.partisannum-3.partisannum
*Dem/Rep elite polarization:
lincom (1.partisannum+1.partisannum#1.elite)-(3.partisannum+3.partisannum#1.elite) 
*difference in mass/elite polarization:
lincom 1.partisannum#1.elite - 3.partisannum#1.elite

reg absval_err_cz_q5q1 ib2.partisannum##elitenum female college nonwhite age3044 age4564 age65plus, robust
est store CZ_Q5
*Dem/Rep mass polarization:
lincom 1.partisannum-3.partisannum
*Dem/Rep elite polarization:
lincom (1.partisannum+1.partisannum#1.elite)-(3.partisannum+3.partisannum#1.elite) 
*difference in mass/elite polarization:
lincom 1.partisannum#1.elite - 3.partisannum#1.elite

reg rel_us_logscore ib2.partisannum##elitenum female college nonwhite age3044 age4564 age65plus, robust
est store US_Log
*Dem/Rep mass polarization:
lincom 1.partisannum-3.partisannum
*Dem/Rep elite polarization:
lincom (1.partisannum+1.partisannum#1.elite)-(3.partisannum+3.partisannum#1.elite) 
*difference in mass/elite polarization:
lincom 1.partisannum#1.elite - 3.partisannum#1.elite

reg rel_cz_logscore ib2.partisannum##elitenum female college nonwhite age3044 age4564 age65plus, robust
est store CZ_Log
*Dem/Rep mass polarization:
lincom 1.partisannum-3.partisannum
*Dem/Rep elite polarization:
lincom (1.partisannum+1.partisannum#1.elite)-(3.partisannum+3.partisannum#1.elite) 
*difference in mass/elite polarization:
lincom 1.partisannum#1.elite - 3.partisannum#1.elite

reg rel_us_brierscore ib2.partisannum##elitenum female college nonwhite age3044 age4564 age65plus, robust
est store US_Brier
*Dem/Rep mass polarization:
lincom 1.partisannum-3.partisannum
*Dem/Rep elite polarization:
lincom (1.partisannum+1.partisannum#1.elite)-(3.partisannum+3.partisannum#1.elite) 
*difference in mass/elite polarization:
lincom 1.partisannum#1.elite - 3.partisannum#1.elite

reg rel_cz_brierscore ib2.partisannum##elitenum female college nonwhite age3044 age4564 age65plus, robust
est store CZ_Brier
*Dem/Rep mass polarization:
lincom 1.partisannum-3.partisannum
*Dem/Rep elite polarization:
lincom (1.partisannum+1.partisannum#1.elite)-(3.partisannum+3.partisannum#1.elite) 
*difference in mass/elite polarization:
lincom 1.partisannum#1.elite - 3.partisannum#1.elite

estout US_Q1 CZ_Q1 US_Q5 CZ_Q5 US_Log CZ_Log US_Brier CZ_Brier using "Tables/B2 Accuracy_Rel.tex", label style(tex) replace varwidth(25) collabels("") cells(b(star fmt(%9.3f)) se(par fmt(%9.3f))) stats(r2 N, fmt(%9.2f %9.0f) labels("N")) starlevels(* 0.05 ** 0.01 *** 0.005)



// TABLE B3: Accuracy_Abs
reg absval_err_us_abs ib2.partisannum##elitenum female college nonwhite age3044 age4564 age65plus, robust
est store US_Absolute
*Dem/Rep mass polarization:
lincom 1.partisannum-3.partisannum
*Dem/Rep elite polarization:
lincom (1.partisannum+1.partisannum#1.elite)-(3.partisannum+3.partisannum#1.elite)
*difference in mass/elite polarization:
lincom 1.partisannum#1.elite - 3.partisannum#1.elite

reg absval_err_state_abs ib2.partisannum##elitenum female college nonwhite age3044 age4564 age65plus, robust
est store State_Absolute
*Dem/Rep mass polarization:
lincom 1.partisannum-3.partisannum
*Dem/Rep elite polarization:
lincom (1.partisannum+1.partisannum#1.elite)-(3.partisannum+3.partisannum#1.elite) 
*difference in mass/elite polarization:
lincom 1.partisannum#1.elite - 3.partisannum#1.elite

estout US_Absolute State_Absolute using "Tables/B3 Accuracy_Abs.tex", label style(tex) replace varwidth(25) collabels("") cells(b(star fmt(%9.3f)) se(par fmt(%9.3f))) stats(r2 N, fmt(%9.2f %9.0f) labels("N")) starlevels(* 0.05 ** 0.01 *** 0.005)



// TABLE B4: Accuracy_Rel_Uncon
* Absval_Q1
rename absval_err_cz_q1q1 quintile_error1
rename absval_err_us_q1q1 quintile_error2
reshape long quintile_error, i(caseid) j(error_num)
gen locale = (error_num == 1)
gen us = (error_num == 2)
reg quintile_error ib2.partisannum##elitenum locale female college nonwhite age3044 age4564 age65plus, robust
est store Absval_Q1
*Dem/Rep mass polarization:
lincom 1.partisannum-3.partisannum
*Dem/Rep elite polarization:
lincom (1.partisannum+1.partisannum#1.elite)-(3.partisannum+3.partisannum#1.elite) 
*difference in mass/elite polarization:
lincom 1.partisannum#1.elite - 3.partisannum#1.elite

use "intermediate_files/2d_brier_log.dta", clear 
* Absval_Q2
rename absval_err_cz_q2q1 quintile_error1
rename absval_err_us_q2q1 quintile_error2
reshape long quintile_error, i(caseid) j(error_num)
gen locale = (error_num == 1)
gen us = (error_num == 2)
reg quintile_error ib2.partisannum##elitenum locale female college nonwhite age3044 age4564 age65plus, robust
est store Absval_Q2
*Dem/Rep mass polarization:
lincom 1.partisannum-3.partisannum
*Dem/Rep elite polarization:
lincom (1.partisannum+1.partisannum#1.elite)-(3.partisannum+3.partisannum#1.elite) 
*difference in mass/elite polarization:
lincom 1.partisannum#1.elite - 3.partisannum#1.elite

use "intermediate_files/2d_brier_log.dta", clear 
* Absval_Q3
rename absval_err_cz_q3q1 quintile_error1
rename absval_err_us_q3q1 quintile_error2
reshape long quintile_error, i(caseid) j(error_num)
gen locale = (error_num == 1)
gen us = (error_num == 2)
reg quintile_error ib2.partisannum##elitenum locale female college nonwhite age3044 age4564 age65plus, robust
est store Absval_Q3
*Dem/Rep mass polarization:
lincom 1.partisannum-3.partisannum
*Dem/Rep elite polarization:
lincom (1.partisannum+1.partisannum#1.elite)-(3.partisannum+3.partisannum#1.elite) 
*difference in mass/elite polarization:
lincom 1.partisannum#1.elite - 3.partisannum#1.elite

use "intermediate_files/2d_brier_log.dta", clear 
* Absval_Q4
rename absval_err_cz_q4q1 quintile_error1
rename absval_err_us_q4q1 quintile_error2
reshape long quintile_error, i(caseid) j(error_num)
gen locale = (error_num == 1)
gen us = (error_num == 2)
reg quintile_error ib2.partisannum##elitenum locale female college nonwhite age3044 age4564 age65plus, robust
est store Absval_Q4
*Dem/Rep mass polarization:
lincom 1.partisannum-3.partisannum
*Dem/Rep elite polarization:
lincom (1.partisannum+1.partisannum#1.elite)-(3.partisannum+3.partisannum#1.elite) 
*difference in mass/elite polarization:
lincom 1.partisannum#1.elite - 3.partisannum#1.elite

use "intermediate_files/2d_brier_log.dta", clear 
* Absval_Q5
rename absval_err_cz_q5q1 quintile_error1
rename absval_err_us_q5q1 quintile_error2
reshape long quintile_error, i(caseid) j(error_num)
gen locale = (error_num == 1)
gen us = (error_num == 2)
reg quintile_error ib2.partisannum##elitenum locale female college nonwhite age3044 age4564 age65plus, robust
est store Absval_Q5
*Dem/Rep mass polarization:
lincom 1.partisannum-3.partisannum
*Dem/Rep elite polarization:
lincom (1.partisannum+1.partisannum#1.elite)-(3.partisannum+3.partisannum#1.elite) 
*difference in mass/elite polarization:
lincom 1.partisannum#1.elite - 3.partisannum#1.elite

use "intermediate_files/2d_brier_log.dta", clear
* Log
rename rel_cz_logscore logscore1
rename rel_us_logscore logscore2
reshape long logscore, i(caseid) j(error_num)
gen locale = (error_num == 1)
gen us = (error_num == 2)
reg logscore ib2.partisannum##elitenum locale female college nonwhite age3044 age4564 age65plus, robust
est store Relative_Log
*Dem/Rep mass polarization:
lincom 1.partisannum-3.partisannum
*Dem/Rep elite polarization:
lincom (1.partisannum+1.partisannum#1.elite)-(3.partisannum+3.partisannum#1.elite) 
*difference in mass/elite polarization:
lincom 1.partisannum#1.elite - 3.partisannum#1.elite

use "intermediate_files/2d_brier_log.dta", clear 

* Brier
rename rel_cz_brierscore brierscore1
rename rel_us_brierscore brierscore2
reshape long brierscore, i(caseid) j(error_num)
gen locale = (error_num == 1)
gen us = (error_num == 2)
reg brierscore ib2.partisannum##elitenum locale female college nonwhite age3044 age4564 age65plus, robust
est store Relative_Brier
*Dem/Rep mass polarization:
lincom 1.partisannum-3.partisannum
*Dem/Rep elite polarization:
lincom (1.partisannum+1.partisannum#1.elite)-(3.partisannum+3.partisannum#1.elite) 
*difference in mass/elite polarization:
lincom 1.partisannum#1.elite - 3.partisannum#1.elite

estout Absval_Q1 Absval_Q2 Absval_Q3 Absval_Q4 Absval_Q5 Relative_Log Relative_Brier using "Tables/B4 Accuracy_Rel_Uncon.tex", label style(tex) replace varwidth(25) collabels("") cells(b(star fmt(%9.3f)) se(par fmt(%9.3f))) stats(r2 N, fmt(%9.2f %9.0f) labels("N")) starlevels(* 0.05 ** 0.01 *** 0.005)


// TABLE B5: Accuracy_Abs_Uncon
use "intermediate_files/2d_brier_log.dta", clear 

rename absval_err_state_abs abs_error1
rename absval_err_us_abs abs_error2
reshape long abs_error, i(caseid) j(scale_num)
gen state = (scale_num == 1)
gen us = (scale_num == 2)
reg abs_error ib2.partisannum##elitenum state female college nonwhite age3044 age4564 age65plus, robust
est store Absolute
*Dem/Rep mass polarization:
lincom 1.partisannum-3.partisannum
*Dem/Rep elite polarization:
lincom (1.partisannum+1.partisannum#1.elite)-(3.partisannum+3.partisannum#1.elite) 
*difference in mass/elite polarization:
lincom 1.partisannum#1.elite - 3.partisannum#1.elite
estout Absolute using "Tables/B5 Accuracy_Abs_Uncon.tex", label style(tex) replace varwidth(25) collabels("") cells(b(star fmt(%9.3f)) se(par fmt(%9.3f))) stats(r2 N, fmt(%9.2f %9.0f) labels("N")) starlevels(* 0.05 ** 0.01 *** 0.005)



// TABLE B6: Accuracy_Rel_Triple
use "intermediate_files/2d_brier_log.dta", clear 
* Absval_Q1
rename absval_err_cz_q1q1 quintile_error1
rename absval_err_us_q1q1 quintile_error2
reshape long quintile_error, i(caseid) j(error_num)
gen locale = (error_num == 1)
gen us = (error_num == 2)
reg quintile_error ib2.partisannum##elitenum##locale female college nonwhite age3044 age4564 age65plus, robust cluster(caseid)
est store Absval_Q1
*National Dem/Rep mass polarization:
lincom 1.partisannum-3.partisannum
*National Dem/Rep elite polarization:
lincom (1.partisannum+1.partisannum#1.elite)-(3.partisannum+3.partisannum#1.elite)
*National difference in mass/elite polarization:
lincom 1.partisannum#1.elite-3.partisannum#1.elite
*Local Dem/Rep mass polarization:
lincom (1.partisannum+1.locale#1.partisannum)-(3.partisannum+1.locale#3.partisannum)
*Local Dem/Rep elite polarization:
lincom (1.partisannum+1.partisannum#1.elite+1.locale#1.partisannum+1.locale#1.partisannum#1.elite)-(3.partisannum+3.partisannum#1.elite+1.locale#3.partisannum+1.locale#3.partisannum#1.elite)
*Local difference in mass/elite polarization:
lincom (1.partisannum#1.elite+1.locale#1.partisannum#1.elite)-(3.partisannum#1.elite+1.locale#3.partisannum#1.elite)
*Difference in Local/National difference in mass/elite polarization
lincom 1.locale#1.partisannum#1.elite-1.locale#3.partisannum#1.elite

use "intermediate_files/2d_brier_log.dta", clear 

* Absval_Q5
rename absval_err_cz_q5q1 quintile_error1
rename absval_err_us_q5q1 quintile_error2
reshape long quintile_error, i(caseid) j(error_num)
gen locale = (error_num == 1)
gen us = (error_num == 2)
reg quintile_error ib2.partisannum##elitenum##locale female college nonwhite age3044 age4564 age65plus, robust cluster(caseid)
est store Absval_Q5
*National Dem/Rep mass polarization:
lincom 1.partisannum-3.partisannum
*National Dem/Rep elite polarization:
lincom (1.partisannum+1.partisannum#1.elite)-(3.partisannum+3.partisannum#1.elite)
*National difference in mass/elite polarization:
lincom 1.partisannum#1.elite-3.partisannum#1.elite
*Local Dem/Rep mass polarization:
lincom (1.partisannum+1.locale#1.partisannum)-(3.partisannum+1.locale#3.partisannum)
*Local Dem/Rep elite polarization:
lincom (1.partisannum+1.partisannum#1.elite+1.locale#1.partisannum+1.locale#1.partisannum#1.elite)-(3.partisannum+3.partisannum#1.elite+1.locale#3.partisannum+1.locale#3.partisannum#1.elite)
*Local difference in mass/elite polarization:
lincom (1.partisannum#1.elite+1.locale#1.partisannum#1.elite)-(3.partisannum#1.elite+1.locale#3.partisannum#1.elite)
*Difference in Local/National difference in mass/elite polarization
lincom 1.locale#1.partisannum#1.elite-1.locale#3.partisannum#1.elite

use "intermediate_files/2d_brier_log.dta", clear

* Log
rename rel_cz_logscore logscore1
rename rel_us_logscore logscore2
reshape long logscore, i(caseid) j(error_num)
gen locale = (error_num == 1)
gen us = (error_num == 2)
reg logscore ib2.partisannum##elitenum##locale female college nonwhite age3044 age4564 age65plus, robust cluster(caseid)
est store Relative_Log
*National Dem/Rep mass polarization:
lincom 1.partisannum-3.partisannum
*National Dem/Rep elite polarization:
lincom (1.partisannum+1.partisannum#1.elite)-(3.partisannum+3.partisannum#1.elite)
*National difference in mass/elite polarization:
lincom 1.partisannum#1.elite-3.partisannum#1.elite
*Local Dem/Rep mass polarization:
lincom (1.partisannum+1.locale#1.partisannum)-(3.partisannum+1.locale#3.partisannum)
*Local Dem/Rep elite polarization:
lincom (1.partisannum+1.partisannum#1.elite+1.locale#1.partisannum+1.locale#1.partisannum#1.elite)-(3.partisannum+3.partisannum#1.elite+1.locale#3.partisannum+1.locale#3.partisannum#1.elite)
*Local difference in mass/elite polarization:
lincom (1.partisannum#1.elite+1.locale#1.partisannum#1.elite)-(3.partisannum#1.elite+1.locale#3.partisannum#1.elite)
*Difference in Local/National difference in mass/elite polarization
lincom 1.locale#1.partisannum#1.elite-1.locale#3.partisannum#1.elite

use "intermediate_files/2d_brier_log.dta", clear 

* Brier
rename rel_cz_brierscore brierscore1
rename rel_us_brierscore brierscore2
reshape long brierscore, i(caseid) j(error_num)
gen locale = (error_num == 1)
gen us = (error_num == 2)
reg brierscore ib2.partisannum##elitenum##locale female college nonwhite age3044 age4564 age65plus, robust cluster(caseid)
est store Relative_Brier
*National Dem/Rep mass polarization:
lincom 1.partisannum-3.partisannum
*National Dem/Rep elite polarization:
lincom (1.partisannum+1.partisannum#1.elite)-(3.partisannum+3.partisannum#1.elite)
*National difference in mass/elite polarization:
lincom 1.partisannum#1.elite-3.partisannum#1.elite
*Local Dem/Rep mass polarization:
lincom (1.partisannum+1.locale#1.partisannum)-(3.partisannum+1.locale#3.partisannum)
*Local Dem/Rep elite polarization:
lincom (1.partisannum+1.partisannum#1.elite+1.locale#1.partisannum+1.locale#1.partisannum#1.elite)-(3.partisannum+3.partisannum#1.elite+1.locale#3.partisannum+1.locale#3.partisannum#1.elite)
*Local difference in mass/elite polarization:
lincom (1.partisannum#1.elite+1.locale#1.partisannum#1.elite)-(3.partisannum#1.elite+1.locale#3.partisannum#1.elite)
*Difference in Local/National difference in mass/elite polarization
lincom 1.locale#1.partisannum#1.elite-1.locale#3.partisannum#1.elite

estout Absval_Q1 Absval_Q5 Relative_Log Relative_Brier using "Tables/B6 Accuracy_Rel_Triple.tex", label style(tex) replace varwidth(25) collabels("") cells(b(star fmt(%9.3f)) se(par fmt(%9.3f))) stats(r2 N, fmt(%9.2f %9.0f) labels("N")) starlevels(* 0.05 ** 0.01 *** 0.005)

use "intermediate_files/2d_brier_log.dta", clear



// TABLE B7: Accuracy_Abs_Triple
rename absval_err_state_abs abs_error1
rename absval_err_us_abs abs_error2
reshape long abs_error, i(caseid) j(scale_num)
gen state = (scale_num == 1)
gen us = (scale_num == 2)
reg abs_error ib2.partisannum##elitenum##state female college nonwhite age3044 age4564 age65plus, robust cluster(caseid)
est store Absval_Absolute
*National Dem/Rep mass polarization:
lincom 1.partisannum-3.partisannum
*National Dem/Rep elite polarization:
lincom (1.partisannum+1.partisannum#1.elite)-(3.partisannum+3.partisannum#1.elite)
*National difference in mass/elite polarization:
lincom 1.partisannum#1.elite-3.partisannum#1.elite
*Local Dem/Rep mass polarization:
lincom (1.partisannum+1.state#1.partisannum)-(3.partisannum+1.state#3.partisannum)
*Local Dem/Rep elite polarization:
lincom (1.partisannum+1.partisannum#1.elite+1.state#1.partisannum+1.state#1.partisannum#1.elite)-(3.partisannum+3.partisannum#1.elite+1.state#3.partisannum+1.state#3.partisannum#1.elite)
*Local difference in mass/elite polarization:
lincom (1.partisannum#1.elite+1.state#1.partisannum#1.elite)-(3.partisannum#1.elite+1.state#3.partisannum#1.elite)
*Difference in Local/National difference in mass/elite polarization
lincom 1.state#1.partisannum#1.elite-1.state#3.partisannum#1.elite

estout Absval_Absolute using "Tables/B7 Accuracy_Abs_Triple.tex", label style(tex) replace varwidth(25) collabels("") cells(b(star fmt(%9.3f)) se(par fmt(%9.3f))) stats(r2 N, fmt(%9.2f %9.0f) labels("N")) starlevels(* 0.05 ** 0.01 *** 0.005)
use "intermediate_files/2d_brier_log.dta", clear



// TABLE B8: Oppfactors
reg err_us_q5q1 ib2.partisannum##elitenum female college nonwhite age3044 age4564 age65plus, robust
est store US_Q5
*Dem/Rep mass polarization:
lincom 1.partisannum-3.partisannum
*Dem/Rep elite polarization:
lincom (1.partisannum+1.partisannum#1.elite)-(3.partisannum+3.partisannum#1.elite) 
*difference in mass/elite polarization:
lincom 1.partisannum#1.elite - 3.partisannum#1.elite

reg err_us_q5q1 ib2.partisannum##elitenum female college nonwhite age3044 age4564 age65plus opp_wealth opp_race opp_edu opp_work opp_nochild, robust
est store US_Q5_Oppfactor
*Dem/Rep mass polarization:
lincom 1.partisannum-3.partisannum
*Dem/Rep elite polarization:
lincom (1.partisannum+1.partisannum#1.elite)-(3.partisannum+3.partisannum#1.elite) 
*difference in mass/elite polarization:
lincom 1.partisannum#1.elite - 3.partisannum#1.elite

reg err_cz_q5q1 ib2.partisannum##elitenum female college nonwhite age3044 age4564 age65plus, robust
est store CZ_Q5
*Dem/Rep mass polarization:
lincom 1.partisannum-3.partisannum
*Dem/Rep elite polarization:
lincom (1.partisannum+1.partisannum#1.elite)-(3.partisannum+3.partisannum#1.elite) 
*difference in mass/elite polarization:
lincom 1.partisannum#1.elite - 3.partisannum#1.elite

reg err_cz_q5q1 ib2.partisannum##elitenum female college nonwhite age3044 age4564 age65plus opp_wealth opp_race opp_edu opp_work opp_nochild, robust
est store CZ_Q5_Oppfactor
*Dem/Rep mass polarization:
lincom 1.partisannum-3.partisannum
*Dem/Rep elite polarization:
lincom (1.partisannum+1.partisannum#1.elite)-(3.partisannum+3.partisannum#1.elite) 
*difference in mass/elite polarization:
lincom 1.partisannum#1.elite - 3.partisannum#1.elite

reg err_us_abs ib2.partisannum##elitenum female college nonwhite age3044 age4564 age65plus, robust
est store US_Absolute
*Dem/Rep mass polarization:
lincom 1.partisannum-3.partisannum
*Dem/Rep elite polarization:
lincom (1.partisannum+1.partisannum#1.elite)-(3.partisannum+3.partisannum#1.elite) 
*difference in mass/elite polarization:
lincom 1.partisannum#1.elite - 3.partisannum#1.elite

reg err_us_abs ib2.partisannum##elitenum female college nonwhite age3044 age4564 age65plus opp_wealth opp_race opp_edu opp_work opp_nochild, robust
est store US_Absolute_Oppfactor
*Dem/Rep mass polarization:
lincom 1.partisannum-3.partisannum
*Dem/Rep elite polarization:
lincom (1.partisannum+1.partisannum#1.elite)-(3.partisannum+3.partisannum#1.elite) 
*difference in mass/elite polarization:
lincom 1.partisannum#1.elite - 3.partisannum#1.elite

reg err_state_abs ib2.partisannum##elitenum female college nonwhite age3044 age4564 age65plus, robust
est store State_Absolute
*Dem/Rep mass polarization:
lincom 1.partisannum-3.partisannum
*Dem/Rep elite polarization:
lincom (1.partisannum+1.partisannum#1.elite)-(3.partisannum+3.partisannum#1.elite) 
*difference in mass/elite polarization:
lincom 1.partisannum#1.elite - 3.partisannum#1.elite

reg err_state_abs ib2.partisannum##elitenum female college nonwhite age3044 age4564 age65plus opp_wealth opp_race opp_edu opp_work opp_nochild, robust
est store State_Absolute_Oppfactor
*Dem/Rep mass polarization:
lincom 1.partisannum-3.partisannum
*Dem/Rep elite polarization:
lincom (1.partisannum+1.partisannum#1.elite)-(3.partisannum+3.partisannum#1.elite) 
*difference in mass/elite polarization:
lincom 1.partisannum#1.elite - 3.partisannum#1.elite

estout US_Q5 US_Q5_Oppfactor CZ_Q5 CZ_Q5_Oppfactor US_Absolute US_Absolute_Oppfactor State_Absolute State_Absolute_Oppfactor using "Tables/B8 Oppfactor.tex", label style(tex) replace varwidth(25) collabels("") cells(b(star fmt(%9.3f)) se(par fmt(%9.3f))) stats(r2 N, fmt(%9.2f %9.0f) labels("N")) starlevels(* 0.05 ** 0.01 *** 0.005)



// TABLE B9: Error_Rel_Triple
rename err_cz_q1q1 quintile_error1
rename err_us_q1q1 quintile_error2
reshape long quintile_error, i(caseid) j(error_num)
gen locale = (error_num == 1)
gen us = (error_num == 2)
reg quintile_error ib2.partisannum##elitenum##locale female college nonwhite age3044 age4564 age65plus, robust cluster(caseid)
est store RelativeQ1
*National Dem/Rep mass polarization:
lincom 1.partisannum-3.partisannum
*National Dem/Rep elite polarization:
lincom (1.partisannum+1.partisannum#1.elite)-(3.partisannum+3.partisannum#1.elite)
*National difference in mass/elite polarization:
lincom 1.partisannum#1.elite-3.partisannum#1.elite
*Local Dem/Rep mass polarization:
lincom (1.partisannum+1.locale#1.partisannum)-(3.partisannum+1.locale#3.partisannum)
*Local Dem/Rep elite polarization:
lincom (1.partisannum+1.partisannum#1.elite+1.locale#1.partisannum+1.locale#1.partisannum#1.elite)-(3.partisannum+3.partisannum#1.elite+1.locale#3.partisannum+1.locale#3.partisannum#1.elite)
*Local difference in mass/elite polarization:
lincom (1.partisannum#1.elite+1.locale#1.partisannum#1.elite)-(3.partisannum#1.elite+1.locale#3.partisannum#1.elite)
*Difference in Local/National difference in mass/elite polarization
lincom 1.locale#1.partisannum#1.elite-1.locale#3.partisannum#1.elite

use "intermediate_files/2d_brier_log.dta", clear
rename err_cz_q5q1 quintile_error1
rename err_us_q5q1 quintile_error2
reshape long quintile_error, i(caseid) j(error_num)
gen locale = (error_num == 1)
gen us = (error_num == 2)
reg quintile_error ib2.partisannum##elitenum##locale female college nonwhite age3044 age4564 age65plus, robust cluster(caseid)
est store RelativeQ5
*National Dem/Rep mass polarization:
lincom 1.partisannum-3.partisannum
*National Dem/Rep elite polarization:
lincom (1.partisannum+1.partisannum#1.elite)-(3.partisannum+3.partisannum#1.elite)
*National difference in mass/elite polarization:
lincom 1.partisannum#1.elite-3.partisannum#1.elite
*Local Dem/Rep mass polarization:
lincom (1.partisannum+1.locale#1.partisannum)-(3.partisannum+1.locale#3.partisannum)
*Local Dem/Rep elite polarization:
lincom (1.partisannum+1.partisannum#1.elite+1.locale#1.partisannum+1.locale#1.partisannum#1.elite)-(3.partisannum+3.partisannum#1.elite+1.locale#3.partisannum+1.locale#3.partisannum#1.elite)
*Local difference in mass/elite polarization:
lincom (1.partisannum#1.elite+1.locale#1.partisannum#1.elite)-(3.partisannum#1.elite+1.locale#3.partisannum#1.elite)
*Difference in Local/National difference in mass/elite polarization
lincom 1.locale#1.partisannum#1.elite-1.locale#3.partisannum#1.elite

estout RelativeQ1 RelativeQ5 using "Tables/B9 Error_Rel_Triple.tex", label style(tex) replace varwidth(25) collabels("") cells(b(star fmt(%9.3f)) se(par fmt(%9.3f))) stats(r2 N, fmt(%9.2f %9.0f) labels("N")) starlevels(* 0.05 ** 0.01 *** 0.005)

// Table B91: Error_Abs_Triple
use "intermediate_files/2d_brier_log.dta", clear 
rename err_state_abs abs_error1
rename err_us_abs abs_error2
reshape long abs_error, i(caseid) j(scale_num)
gen state = (scale_num == 1)
gen us = (scale_num == 2)
reg abs_error ib2.partisannum##elitenum##state female college nonwhite age3044 age4564 age65plus, robust cluster(caseid)
est store Absolute
*National Dem/Rep mass polarization:
lincom 1.partisannum-3.partisannum
*National Dem/Rep elite polarization:
lincom (1.partisannum+1.partisannum#1.elite)-(3.partisannum+3.partisannum#1.elite)
*National difference in mass/elite polarization:
lincom 1.partisannum#1.elite-3.partisannum#1.elite
*Local Dem/Rep mass polarization:
lincom (1.partisannum+1.state#1.partisannum)-(3.partisannum+1.state#3.partisannum)
*Local Dem/Rep elite polarization:
lincom (1.partisannum+1.partisannum#1.elite+1.state#1.partisannum+1.state#1.partisannum#1.elite)-(3.partisannum+3.partisannum#1.elite+1.state#3.partisannum+1.state#3.partisannum#1.elite)
*Local difference in mass/elite polarization:
lincom (1.partisannum#1.elite+1.state#1.partisannum#1.elite)-(3.partisannum#1.elite+1.state#3.partisannum#1.elite)
*Difference in Local/National difference in mass/elite polarization
lincom 1.state#1.partisannum#1.elite-1.state#3.partisannum#1.elite

estout Absolute using "Tables/B91 Error_Abs_Triple.tex", label style(tex) replace varwidth(25) collabels("") cells(b(star fmt(%9.3f)) se(par fmt(%9.3f))) stats(r2 N, fmt(%9.2f %9.0f) labels("N")) starlevels(* 0.05 ** 0.01 *** 0.005)

// TABLE B92: Perception_Relative
use "intermediate_files/2d_brier_log.dta", clear
reg cz_per_q1q1 q1q1 ib2.partisannum##elitenum female college nonwhite age3044 age4564 age65plus, robust
est store cz_per_q1q1
*Dem/Rep mass polarization:
lincom 1.partisannum-3.partisannum
*Dem/Rep elite polarization:
lincom (1.partisannum+1.partisannum#1.elite)-(3.partisannum+3.partisannum#1.elite) 
*difference in mass/elite polarization:
lincom 1.partisannum#1.elite - 3.partisannum#1.elite

reg cz_per_q5q1 q5q1 ib2.partisannum##elitenum female college nonwhite age3044 age4564 age65plus, robust
est store cz_per_q5q1
*Dem/Rep mass polarization:
lincom 1.partisannum-3.partisannum
*Dem/Rep elite polarization:
lincom (1.partisannum+1.partisannum#1.elite)-(3.partisannum+3.partisannum#1.elite) 
*difference in mass/elite polarization:
lincom 1.partisannum#1.elite - 3.partisannum#1.elite

estout cz_per_q1q1 cz_per_q5q1 using "Tables/B92 Perception_Relative.tex", label style(tex) replace varwidth(25) collabels("") cells(b(star fmt(%9.3f)) se(par fmt(%9.3f))) stats(r2 N, fmt(%9.2f %9.0f) labels("N")) starlevels(* 0.05 ** 0.01 *** 0.005) 



// TABLE B93: Perception_Absolute
use "intermediate_files/2d_brier_log.dta", clear
reg state_per_abs cohort_mean ib2.partisannum##elitenum female college nonwhite age3044 age4564 age65plus, robust
est store state_per_abs
*Dem/Rep mass polarization:
lincom 1.partisannum-3.partisannum
*Dem/Rep elite polarization:
lincom (1.partisannum+1.partisannum#1.elite)-(3.partisannum+3.partisannum#1.elite) 
*difference in mass/elite polarization:
lincom 1.partisannum#1.elite - 3.partisannum#1.elite
estout state_per_abs using "Tables/B93 Perception_Absolute.tex", label style(tex) replace varwidth(25) collabels("") cells(b(star fmt(%9.3f)) se(par fmt(%9.3f))) stats(r2 N, fmt(%9.2f %9.0f) labels("N")) starlevels(* 0.05 ** 0.01 *** 0.005) 



// TABLE B94: Perception_Stacked
use "intermediate_files/2d_brier_log.dta", clear
rename cz_per_q1q1 quintile_per1
rename us_per_q1q1 quintile_per2
reshape long quintile_per, i(caseid) j(per_num)
gen locale = (per_num == 1)
gen us = (per_num == 2)
reg quintile_per c.q1q1##locale ib2.partisannum##elitenum female college nonwhite age3044 age4564 age65plus, robust cluster(caseid)
est store RelativeQ1
*true local mobility relationship to perceptions of national mobility:
lincom c.q1q1
*true local mobility relationship to perceptions of local mobility:
lincom c.q1q1+c.q1q1#1.locale
*difference in relationship of true local mobility to perceptions of local mobility (versus national)
lincom c.q1q1#1.locale


use "intermediate_files/2d_brier_log.dta", clear

rename cz_per_q5q1 quintile_per1
rename us_per_q5q1 quintile_per2
reshape long quintile_per, i(caseid) j(per_num)
gen locale = (per_num == 1)
gen us = (per_num == 2)
reg quintile_per c.q5q1##locale ib2.partisannum##elitenum female college nonwhite age3044 age4564 age65plus, robust cluster(caseid)
est store RelativeQ5
*true local mobility relationship to perceptions of national mobility:
lincom c.q5q1
*true local mobility relationship to perceptions of local mobility:
lincom c.q5q1+c.q5q1#1.locale
*difference in relationship of true local mobility to perceptions of local mobility (versus national)
lincom c.q5q1#1.locale

use "intermediate_files/2d_brier_log.dta", clear

rename state_per_abs abs_per1
rename us_per_abs abs_per2
reshape long abs_per, i(caseid) j(scale_num)
gen state = (scale_num == 1)
gen us = (scale_num == 2)
reg abs_per c.cohort_mean##state ib2.partisannum##elitenum female college nonwhite age3044 age4564 age65plus, robust cluster(caseid)
est store Absolute
*true state mobility relationship to perceptions of national mobility:
lincom c.cohort_mean
*true state mobility relationship to perceptions of state mobility:
lincom c.cohort_mean+c.cohort_mean#1.state
*difference in relationship of true state mobility to perceptions of state mobility (versus national)
lincom c.cohort_mean#1.state

estout RelativeQ1 RelativeQ5 Absolute using "Tables/B94 Perception_Stacked.tex", label style(tex) replace varwidth(25) collabels("") cells(b(star fmt(%9.3f)) se(par fmt(%9.3f))) stats(r2 N, fmt(%9.2f %9.0f) labels("N")) starlevels(* 0.05 ** 0.01 *** 0.005)

use "intermediate_files/2d_brier_log.dta", clear

// TABLE B95: Error_Rel_Uncon
use "intermediate_files/2d_brier_log.dta", clear
* Q1
rename err_cz_q1q1 quintile_error1
rename err_us_q1q1 quintile_error2
reshape long quintile_error, i(caseid) j(error_num)
gen locale = (error_num == 1)
gen us = (error_num == 2)
reg quintile_error ib2.partisannum##elitenum locale female college nonwhite age3044 age4564 age65plus, robust
est store Q1
*Dem/Rep mass polarization:
lincom 1.partisannum-3.partisannum
*Dem/Rep elite polarization:
lincom (1.partisannum+1.partisannum#1.elite)-(3.partisannum+3.partisannum#1.elite) 
*difference in mass/elite polarization:
lincom 1.partisannum#1.elite - 3.partisannum#1.elite

use "intermediate_files/2d_brier_log.dta", clear 
* Q2
rename err_cz_q2q1 quintile_error1
rename err_us_q2q1 quintile_error2
reshape long quintile_error, i(caseid) j(error_num)
gen locale = (error_num == 1)
gen us = (error_num == 2)
reg quintile_error ib2.partisannum##elitenum locale female college nonwhite age3044 age4564 age65plus, robust
est store Q2
*Dem/Rep mass polarization:
lincom 1.partisannum-3.partisannum
*Dem/Rep elite polarization:
lincom (1.partisannum+1.partisannum#1.elite)-(3.partisannum+3.partisannum#1.elite) 
*difference in mass/elite polarization:
lincom 1.partisannum#1.elite - 3.partisannum#1.elite

use "intermediate_files/2d_brier_log.dta", clear 
* Q3
rename err_cz_q3q1 quintile_error1
rename err_us_q3q1 quintile_error2
reshape long quintile_error, i(caseid) j(error_num)
gen locale = (error_num == 1)
gen us = (error_num == 2)
reg quintile_error ib2.partisannum##elitenum locale female college nonwhite age3044 age4564 age65plus, robust
est store Q3
*Dem/Rep mass polarization:
lincom 1.partisannum-3.partisannum
*Dem/Rep elite polarization:
lincom (1.partisannum+1.partisannum#1.elite)-(3.partisannum+3.partisannum#1.elite) 
*difference in mass/elite polarization:
lincom 1.partisannum#1.elite - 3.partisannum#1.elite

use "intermediate_files/2d_brier_log.dta", clear 
* Q4
rename err_cz_q4q1 quintile_error1
rename err_us_q4q1 quintile_error2
reshape long quintile_error, i(caseid) j(error_num)
gen locale = (error_num == 1)
gen us = (error_num == 2)
reg quintile_error ib2.partisannum##elitenum locale female college nonwhite age3044 age4564 age65plus, robust
est store Q4
*Dem/Rep mass polarization:
lincom 1.partisannum-3.partisannum
*Dem/Rep elite polarization:
lincom (1.partisannum+1.partisannum#1.elite)-(3.partisannum+3.partisannum#1.elite) 
*difference in mass/elite polarization:
lincom 1.partisannum#1.elite - 3.partisannum#1.elite

use "intermediate_files/2d_brier_log.dta", clear 
* Q5
rename err_cz_q5q1 quintile_error1
rename err_us_q5q1 quintile_error2
reshape long quintile_error, i(caseid) j(error_num)
gen locale = (error_num == 1)
gen us = (error_num == 2)
reg quintile_error ib2.partisannum##elitenum locale female college nonwhite age3044 age4564 age65plus, robust
est store Q5
*Dem/Rep mass polarization:
lincom 1.partisannum-3.partisannum
*Dem/Rep elite polarization:
lincom (1.partisannum+1.partisannum#1.elite)-(3.partisannum+3.partisannum#1.elite) 
*difference in mass/elite polarization:
lincom 1.partisannum#1.elite - 3.partisannum#1.elite


estout Q1 Q2 Q3 Q4 Q5 using "Tables/B95 Error_Rel_Uncon.tex", label style(tex) replace varwidth(25) collabels("") cells(b(star fmt(%9.3f)) se(par fmt(%9.3f))) stats(r2 N, fmt(%9.2f %9.0f) labels("N")) starlevels(* 0.05 ** 0.01 *** 0.005)

// TABLE B95.2: Error_Abs_Uncon
use "intermediate_files/2d_brier_log.dta", clear
* Q1
rename err_state_abs quintile_error1
rename err_us_abs quintile_error2
reshape long quintile_error, i(caseid) j(error_num)
gen state = (error_num == 1)
gen us = (error_num == 2)
reg quintile_error ib2.partisannum##elitenum state female college nonwhite age3044 age4564 age65plus, robust
est store abs
*Dem/Rep mass polarization:
lincom 1.partisannum-3.partisannum
*Dem/Rep elite polarization:
lincom (1.partisannum+1.partisannum#1.elite)-(3.partisannum+3.partisannum#1.elite) 
*difference in mass/elite polarization:
lincom 1.partisannum#1.elite - 3.partisannum#1.elite


estout abs using "Tables/B95 Error_Abs_Uncon.tex", label style(tex) replace varwidth(25) collabels("") cells(b(star fmt(%9.3f)) se(par fmt(%9.3f))) stats(r2 N, fmt(%9.2f %9.0f) labels("N")) starlevels(* 0.05 ** 0.01 *** 0.005)
